# 使用with关键字，可以不用手动关闭文件

# with open('123.txt', 'r', encoding='utf-8') as file:
#     print(file.read())

with open('123.txt', 'a', encoding='utf-8') as file:
    file.write('123\n456')

with open('123.txt', 'r', encoding='utf-8') as file:
    print(file.read())
